<?php
session_start();
	include('../controller/functions.php');
	User::connection();

$userArr	= array('admin');
	if(!in_array($_SESSION['user'],$userArr)) {
	User::validSession();

}
if ($_GET['q'] == 'logout') 
{
	User::user_logout();
	print '		
			<script type="text/javascript">		
			window.location = "../login_r.php";
			</script>
			';

}


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<link rel="shortcut icon" href="../images/fav.ico">
<link rel="icon" type="image/gif" href="../images/fav.ico">
<title>CMS | Create New WebPage</title>
</head>
<link rel="stylesheet" href="../css/style2.css" type="text/css" charset="utf-8" />
    <link rel="stylesheet" href="../css/front.css" type="text/css" charset="utf-8" />
    	<link type="text/css" href="../css/demo.css" rel="stylesheet" />
           <link rel="stylesheet" href="../css/general.css" type="text/css" charset="utf-8" />




<? 

$type = $_GET['type'];
//switch o if?
	//Makabayan Section
	if($type == 'home'):
		$typeCat = 'viewHome';
		$typeCategory = 'Home';
		//Filipino Section
		elseif($type == 'about'):
		$typeCat = 'viewAbout';
		$typeCategory = 'About';
		//English Section
		elseif($type == 'annouce'):
		$typeCat = 'viewAnnouce';
		$typeCategory = 'Annoucement';
		//Math Section
		elseif($type == 'news'):
		$typeCat = 'viewEvents';
		$typeCategory = 'News';
		//Contact Us Section
		elseif($type == 'contact'):
		$typeCat = 'viewContact';
		$typeCategory = 'Contact';
endif;

if(isset($_POST['save'])):

		$userid = $_SESSION['curuser'];
		$topTitle = $_POST['topTitle'];
		$topContent = $_POST['topContent'];		
		$createby = $_SESSION['us'];
		$topDate = date("F j, Y H:i:s");

	if($topTitle==NULL || $topContent==NULL){
		
		print "'.$userid.'";
		print "'.$topTitle.'";
		print "'.$topContent.'";
		print "'.$createby.'";
		print "'.$topDate.'";
		print "'.$type.'";
		
		print '
		
		<script type="text/javascript">
		
		alert("Please complete the fields.");
		window.location = "createPage.php?type='.$type.'";
		</script>
		
		
		';
		
	}
		else{
		
			
		$ins = mysql_query("INSERT INTO tblcms (cmsType,cmsEditor,cmsContent,cmsTitle,cmsDate,cmsEditorBy) VALUES('$type','$createby','$topContent','$topTitle','$topDate', '$userid')") or die (mysql_error());
		
			if($type=='home')
			{
			
			print '
			
			<script type="text/javascript">
			
			window.location = "viewHome.php";
			</script>
			
			
			';
			}
			
			else if($type=='about')
			{
			
			print '
			
			<script type="text/javascript">
			
			window.location = "viewAbout.php";
			</script>
			
			
			';
			}
			else if($type=='annouce')
			{
			
			print '
			
			<script type="text/javascript">
			
			window.location = "viewAnnouce.php";
			</script>
			
			
			';
			}
			else if($type=='gallery')
			{
			
			print '
			
			<script type="text/javascript">
			
			window.location = "viewGallery.php";
			</script>
			
			
			';
			}
				else if($type=='contact')
			{
			
			print '
			
			<script type="text/javascript">
			
			window.location = "viewContact.php";
			</script>
			
			
			';
			}
		
		
		else if($type=='news')
			{
			
			print '
			
			<script type="text/javascript">
			
			window.location = "viewEvents.php";
			</script>
			
			
			';
			}
		
		
		}
						
      	             
endif;	
?>


<body>
<div id="page">
<div id="wrapper">
        
        		   <div class="header_top" id="header_top"> </div>
  </div>
  <div class="header2"></div> 
	<div class="header"><!--open logo -->
		  </div><!--end header -->
	<!-- close logo-->
<!-- hide the client inquiries php-->
    <?php
    echo '<div id="nav">';
    echo '<div class="underlinemenu">';
	include('menu_view.php');
	echo '</div>';
    echo '</div>';
	?>
    <div id="header_in"> <!--open header -->
    <p> </p>
    
    <table width="100%" height="56">
     <tr>
       <td width="317" align="left" class="date"> 
        <? User::oras(); ?>
        </td>
            
       <td width="388" align="right"><? User::showPic(); ?></td>
       <td width="279">&nbsp;&nbsp;<? User::showUser(); ?>        </td>
       </tr>
   </table>
     
  
    </div>
    <div id="ex">
    </div>
    
      <p> </p>
       <div id="body"> <!--open body -->
    
	 <div id="sidebar"> 
           <!-- <div id="chef_ind">open chef -->
        <div id="welcome"> <!--open welcome -->
               <!-- <h2 class="guilded"></h2> -->
        </div> <!--close welcome-->

<? echo '<p class="more">';
echo '';
 
   require('sideBar.php');
    
echo'</p>';
?>
  </div>
        
      <!--</div>close left -->
      
          <div id="content"> 
      <div class="desriptionHeader"> <!--open right-->
      <div id="container">
    
         <div class="post3_students"><h2>Website Management</h2> </div>
      
            <div class="desriptionHeader"> <!--open right-->
       <div class="postbg1"><!--open booking -->
        <div align="center" class="mainbox">

                  <form id="form2" name="form2" method="post" action="">
                    <table width="600" border="0">
                    <tr>
                        <td colspan="6">
                    <b>CMS</b>  <img width="25" height="15" border="0" src="../images/arrow.png"> <a class="siteloc" href="<? print $typeCat; ?>.php"><? print $typeCategory; ?></a>  <img width="25" height="15" border="0" src="../images/arrow.png"> <a class="siteloc" href="#">New Web Page</a>
                        </td>
                    </tr>
                    <tr>
                        <td align="left" background="catbg.png" colspan="5" class="cat"><? print $topTitle; ?></td>
                    </tr>
                    <tr>
                  <td height="23" class="label">POST A NEW PAGE</td>
                	</tr>
                      <tr>
                        <td>&nbsp;</td>
                      </tr>
                      <tr>
                
				
			
			
                        <td class="extra"><b>Title:</b><input name="topTitle" type="text" id="topTitle" size="113" value="<? print $topTitle; ?>" /></td>
                	
                     
                    </tr>
                      <tr>
                        <td>&nbsp; </td>
                      </tr>
                      <tr>
                        <td><textarea id="topContent" name="topContent" rows="15" cols="80" style="width: 70%">
                          <? print $topContent; ?>
                          </textarea>
   
                          </td>
                      </tr>
                      <tr>
                        <td align="center"><label>
                        <!--<input type="button" name="Submit" value="toggle editor" onclick="javascript:toggleEditor('elm1');" />--> 
                         <input value='Back' type='button' id='btnb' onclick='history.go(-1); return false;' />
                          <input type="submit" name="save" id="save" value="Submit" />
                        </label></td>
                      </tr>
                    </table>
            </form>    
              </div>   
</div><!--close booking -->
   </div><!--close desc -->
   
          
     				
	  </div><!--close booking -->
   </div><!--close desc -->
    	</div> <!--close right-->
      <div class="clear">&nbsp;</div>
 <!-- footer-->
 <?php 
	  echo '<div id="footer">';
     include('footer_view.php');
      echo '</div>';	
	  ?>

    </div><!-- close body-->
</div><!-- close page-->


</body>
</html>



	

